home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar / 1995 / JUL / BT9507 / memos.pas < prev   
Pascal/Delphi Source File  |  1995-05-19  |  1KB  |  46 lines

  1. unit Memos;
  2.  
  3. interface
  4.  
  5. uses WinProcs, SysUtils, StdCtrls, Dialogs, Messages;
  6.  
  7. {Get the line number and column number the cursor
  8.  is positioned at in the memo.}
  9. procedure GetMemoLineCol(Memo: TCustomMemo;
  10.                    var MemoLine, MemoCol: Integer );
  11.  
  12. {Set the cursor position in a memo to the specified
  13.  line and column.}
  14. procedure MemoCursorTo(Memo: TCustomMemo;
  15.                    MemoLine, MemoCol: Integer );
  16.  
  17. implementation
  18.  
  19. { Get the line number and column number the cursor
  20.   is positioned at in the memo. }
  21. procedure GetMemoLineCol(Memo: TCustomMemo;
  22.                          var MemoLine, MemoCol: Integer);
  23. begin
  24.   with Memo do
  25.   begin
  26.     { Get the line number of the line that
  27.       contains the cursor. }
  28.     MemoLine := SendMessage(Handle, EM_LINEFROMCHAR,
  29.                             SelStart, 0);
  30.     { Get the offset of the cursor in the line. }
  31.     MemoCol := SelStart - SendMessage(Handle, EM_LINEINDEX,
  32.                                       MemoLine, 0) + 1;
  33.   end;
  34. end;
  35.  
  36. {Set the cursor position in a memo to the specified
  37.  line and column.}
  38. procedure MemoCursorTo(Memo: TCustomMemo;
  39.                    MemoLine, MemoCol: Integer );
  40. begin
  41.   Memo.SelStart :=
  42.       SendMessage(Memo.Handle, EM_LINEINDEX,
  43.       MemoLine, 0) + MemoCol - 1;
  44. end;
  45.  
  46. end.